package com.pz.art.service.impl;

import com.pz.art.domain.AssoEvents;
import com.pz.art.domain.AssoMemberInitiation;
import com.pz.art.mapper.ApplyAssociationMapper;
import com.pz.art.mapper.MemberMapper;
import com.pz.art.service.ApplyAssociationService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@Primary
public class ApplyAssociationServiceImpl implements ApplyAssociationService {

    @Autowired
    private ApplyAssociationMapper applyAssociationMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Override
    public List<AssoMemberInitiation> getSelectMemberInitiation(AssoMemberInitiation assoMemberInitiation) {
        List<AssoMemberInitiation> assoMemberInitiationList = applyAssociationMapper.selectMemberInitiation(assoMemberInitiation);
        GetTypename(assoMemberInitiationList);
        return applyAssociationMapper.selectMemberInitiation(assoMemberInitiation);
    }

    @Override
    public List<AssoMemberInitiation> getSelectUnitInitiation(AssoMemberInitiation assoMemberInitiation) {
        List<AssoMemberInitiation> assoMemberInitiationList = applyAssociationMapper.selectUnitInitiation(assoMemberInitiation);
        GetTypename(assoMemberInitiationList);
        return applyAssociationMapper.selectUnitInitiation(assoMemberInitiation);
    }

    @Override
    public void updataApprove(AssoMemberInitiation assoMemberInitiation) {
        assoMemberInitiation.setStatus(assoMemberInitiation.getStatus());
        assoMemberInitiation.setMember_id(assoMemberInitiation.getMember_id());
        applyAssociationMapper.approveUpdate(assoMemberInitiation);
        if (assoMemberInitiation.getStatus() == 2){
            memberMapper.updatememberinitiation(assoMemberInitiation.getStatus(), assoMemberInitiation.getMember_id(),assoMemberInitiation.getType(), DateUtils.getNowDate());
        }
    }

    private void GetTypename(List<AssoMemberInitiation> assoMemberInitiationList) {
        for (AssoMemberInitiation assoMember : assoMemberInitiationList){
            switch (assoMember.getType()){
                case "1":
                    assoMember.setTeam_name("运动员");
                    break;
                case "2":
                    assoMember.setTeam_name("教练员");
                    break;
                case "3":
                    assoMember.setTeam_name("裁判员");
                    break;
                default:
                    assoMember.setTeam_name("业余运动员");
                    break;
            }
        }
    }
}
